//
//  MainViewController.swift
//  YeKa
//
//  Created by Gina on 15/10/13.
//  Copyright © 2015年 Gina. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

   
    // 用户是否登录
    var userLogin = true
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 添加三个根视图
        addChildViewControllers()
    }
    
    
    
    private func addChildViewControllers() {
        
        let wanVc = loadStroyboard("WanView", title: "玩", itemIcon: "icon_left_homepage_a")
        let juVc = loadStroyboard("JuView", title: "聚", itemIcon: "icon_left_addfriend_a")
        var meVc: UIViewController
        if userLogin {
            meVc = loadStroyboard("MeView", title: "我", itemIcon: "icon_left_setting_a")
        } else {
            
            let sb = UIStoryboard(name: "LoginView", bundle: NSBundle.mainBundle())
            let nav = UINavigationController(rootViewController: sb.instantiateInitialViewController()!)
            
            nav.title = "我"
            nav.tabBarItem.image = UIImage(named: "icon_left_setting_a")
            
            meVc = nav
            
        }
        viewControllers = [wanVc, juVc, meVc]

        
        
    }
     
    private func loadStroyboard(storyboardName: String,title:String,itemIcon:String) -> UINavigationController {
        
        let sb = UIStoryboard(name: storyboardName, bundle: NSBundle.mainBundle())
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        nav.title = title
        nav.tabBarItem.image = UIImage(named: itemIcon)
        
        return nav
        
    }
    
    
    

}
